import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
import './assets/css/reset.css'
import ElementUI from 'element-ui'
import dbSDK from './assets/js/indexedDB_sdk.js'
import clientSDK from './assets/js/client_sdk.js'
import 'element-ui/lib/theme-chalk/index.css'
import constVar from './global/const/index'
import './assets/css/index.scss'
import './assets/css/media.scss'
import client from './utils/client'
import loading from './global/loading/index'
import mydialog from './global/dialog/dialog'
import log from './global/log/index'
import './utils/systemdialog'
import downloadmask from './global/loadingmask/loadingmask'



window.$Vue = new Vue()
var VueTouch = require('vue-touch')
Vue.use(VueTouch, { name: 'v-touch' })
Vue.use(ElementUI)
Vue.prototype.$db_sdk = dbSDK
Vue.prototype.$clientSDK = clientSDK
Vue.prototype.$client = client
Vue.prototype.$CONST = constVar
Vue.prototype.$dialog = mydialog
Vue.prototype.$downloadmask = downloadmask
require('./global/ini/index.js')
if (!process.env.IS_WEB) Vue.use(require('vue-electron'))
Vue.config.productionTip = false
const { scaleFactor, size } = require('electron').remote.screen.getPrimaryDisplay();
if (scaleFactor >= 1 || size.width < 1440) {
  const webFrame = require('electron').webFrame;
  const zoomFactor = window.innerWidth / 1440
  webFrame.setZoomFactor(zoomFactor);
}
let lockArouse = false
const path = require('path')
const exePath = process.env.NODE_ENV !== 'production' ? path.join(process.cwd(), 'bos_builder', 'ExecOSK.exe') : 'ExecOSK.exe'
console.log(exePath)
const arouseFun = function (a) {
  const arouse = window.localStorage.getItem('arouse')
  if (arouse === 'true' && !lockArouse) {
    const exec = require('child_process').exec
    lockArouse = true
    exec(exePath, (err) => {
      //成功执行的回调
      if (!err) {
        lockArouse = false
      }
    })
  }
}
const arouseFunTouch = function (e) {
  const arouse = window.localStorage.getItem('arouse')
  if (arouse === null) {
    Vue.prototype
      .$dialog({
        title: '温馨提示',
        confirm: '开启',
        cancel: '取消',
        message: '检测到您正在使用触摸屏，请问是否开启系统软键盘？开启后我们将自动为您打开软键盘，不需要此功能时可在设置中关闭。',
      })
      .then((_) => {
        window.localStorage.setItem('arouse', true)
        e.target.focus()
        const exec = require('child_process').exec
        exec(exePath)
      })
      .catch((_) => {
        window.localStorage.setItem('arouse', false)
      })
  } else {
    if (arouse === 'true' && !lockArouse) {
      const exec = require('child_process').exec
      lockArouse = true
      exec(exePath, (err) => {
        //成功执行的回调
        if (!err) {
          lockArouse = false
        }
      })
    }
  }
}
Vue.directive('arouse', {
  bind (el, binding) {
    el.addEventListener('touchstart', arouseFunTouch)
    el.addEventListener('mousedown', arouseFun)
  },
  unbind (el) {
    el.removeEventListener('mousedown', arouseFun)
    el.removeEventListener('touchstart', arouseFun)
  },
})

/* eslint-disable no-new */
export default new Vue({
  components: { App },
  router,
  store,
  template: '<App/>',
}).$mount('#app')
